package org.lanqiao.api.product;

import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.lanqiao.common.Constants;
import org.lanqiao.common.JsonResult;
import org.lanqiao.common.JsonResultWriter;
import org.lanqiao.pojo.ProductPOJO;
import org.lanqiao.service.ProductServiceImpl;

/**
 * Servlet implementation class DetailServlet
 */
/**
 * 通过productCode查商品名，描述，图片
 * @author luqian1000
 *
 */
@WebServlet("/api/product/detail")
public class DetailServlet extends HttpServlet {
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		ProductPOJO product =new ProductPOJO();
		product.setProductCode(request.getParameter("productCode"));
		JsonResult result=null;
		
		try {
			ProductServiceImpl productService=new ProductServiceImpl();
			List<LinkedHashMap<String, Object>> list=productService.descriptionService(product);
			if(list.size()>0) {
				result=new JsonResult("查询成功",Constants.STATUS_SUCCESS,list);
			}else {
				result=new JsonResult("查询失败",Constants.STATUS_UNFOUND);
			}
		}catch(Exception e){
			result=new JsonResult("查询异常",Constants.STATUS_FAILURE);
		}
		JsonResultWriter.writer(response,result);
	}

}
